trigger OpportunityOnUpdateTrade on Opportunity (before insert, before update) {
	
	for(Opportunity opp : Trigger.new){		
		boolean needUpdate = false;
		if(Trigger.isInsert){
				needUpdate = true;
		}else if(Trigger.isUpdate){
			//judge port or trade term is change
			Opportunity oldOpp = Trigger.oldMap.get(opp.id);
			if((oldOpp.port__c != opp.port__c) || (oldOpp.tradeterm__c != opp.tradeterm__c)) {
				needUpdate = true;
			}
		}
		if(needUpdate && opp.port__c!=null && opp.tradeterm__c!=null){
			//get trade parameter
			double param = TradeUtils.getTradeParameterById(opp.port__c, opp.tradeterm__c);
			//set trade parameter.	
			opp.tradeParameter__c = param;
		}	
	}	
}